package com.achievement.service.impl;

import com.achievement.domain.dto.honor.ReviewResultDTO;
import com.achievement.domain.entity.ReviewResultEntity;
import com.achievement.domain.param.honor.ReviewResultParam;
import com.achievement.domain.vo.honor.ReviewResultVO;
import com.achievement.domain.vo.honor.ReviewResultWithReviewStandardVO;
import com.achievement.mapper.ReviewResultMapper;
import com.achievement.mappings.ReviewResultMapping;
import com.achievement.service.IReviewResultService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class ReviewResultServiceImpl extends ServiceImpl<ReviewResultMapper, ReviewResultEntity> implements IReviewResultService {
    @Autowired
    private ReviewResultMapping mapping;
    @Autowired
    private ReviewResultMapper mapper;

    @Override
    public List<ReviewResultVO> selectByPage(ReviewResultParam param) {
        LambdaQueryWrapper<ReviewResultEntity> queryWrapper = new LambdaQueryWrapper();
        List<ReviewResultEntity> list=new ArrayList<>();
        queryWrapper.eq(StringUtils.isNotEmpty(param.getReviewStandardId()), ReviewResultEntity::getReviewStandardId, param.getReviewStandardId());
        list = this.list(queryWrapper);
        List<ReviewResultVO> voList = list.stream().map(mapping::entity2Vo).collect(Collectors.toList());
        return voList;
    }
    @Override
    public List<ReviewResultEntity> getListByConditions(ReviewResultDTO patentDTO) {
        QueryWrapper<ReviewResultEntity> queryWrapper = new QueryWrapper();
        List<ReviewResultEntity> list = this.list(queryWrapper);
        return list;
    }
    @Override
    public List<ReviewResultVO> getListByQueryWrapper(LambdaQueryWrapper<ReviewResultEntity> queryWrapper) {
        List<ReviewResultEntity> list = this.list(queryWrapper);
        List<ReviewResultVO> voList = list.stream().map(mapping::entity2Vo).collect(Collectors.toList());
        return voList;
    }

    @Override
    public ReviewResultVO getInfoById(String id) {
        ReviewResultEntity entity = this.getById(id);
        ReviewResultVO ReviewResultVO=mapping.entity2Vo(entity);
        return ReviewResultVO;
    }

    @Override
    public boolean add(ReviewResultDTO dto) {
        ReviewResultEntity entity = mapping.dto2Entity(dto);
        return this.save(entity);
    }


    @Override
    public boolean update(ReviewResultDTO dto) {
        ReviewResultEntity entity = mapping.dto2Entity(dto);
        return this.updateById(entity);
    }

    @Override
    public boolean batchRemove(List<String> ids) {
        boolean returnResult=false;
        returnResult=this.removeByIds(ids);
        return returnResult;
    }
    @Override
    public  List<ReviewResultWithReviewStandardVO>  reviewResultWithReviewStandardListById(@Param("reviewSchemeId") String reviewSchemeId){
        return mapper.reviewResultWithReviewStandardListById(reviewSchemeId);
    }
}
